package RestWS;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import model.Customer;

import convert.*;
import dao.CustomerDao;

@Path("/customer")
public class CustomerResource {

	@GET
	@Path("/info1")
	@Produces(MediaType.APPLICATION_JSON)
	public List<CustomerBN> getCustomerList() {
		System.out.println("$$$$$$$$$$$$$$$$$$$$$ call Get CUstomer....$$$$");
		List<CustomerBN> customerBnList = customerBNsHelp();

		return customerBnList;
	}

	@GET
	@Path("/info2")
	@Produces(MediaType.APPLICATION_XML)
	public List<CustomerBN> getCustomerListall() {
		System.out.println("$$$$$$$$$$$$$$$$$$$$$ call Get CUstomer....$$$$");
		List<CustomerBN> customerBnList = customerBNsHelp();

		return customerBnList;
	}

	@GET
	@Path("/info3")
	@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
	public List<CustomerBN> getCustomerListxml() {
		System.out.println("$$$$$$$$$$$$$$$$$$$$$ call Get CUstomer....$$$$");
		List<CustomerBN> customerBnList = customerBNsHelp();

		return customerBnList;
	}

	@DELETE
	@Path("/info4")
	public void getCustomerDelete() {
		System.out.println("$$$$$$$$$$$$$$$$$$$$$ call Get CUstomer....$$$$");
		System.out.println("this is very easy api @@@");
	}
	
	
	
	@DELETE
	@Path("/info10")
	public void myappdev() {
		System.out.println("$$$$$$$$$$$$$$$$$$$$$ call Get myappdev....$$$$");
		System.out.println("this is myappdev easy api @@@");
	}
	

	public List<CustomerBN> customerBNsHelp() {

		List<CustomerBN> bns = new ArrayList<CustomerBN>();

		CustomerDao customerDao = new CustomerDao();

		List<Customer> customers = customerDao.getCustomerList();

		Iterator<Customer> iterator = customers.iterator();

		while (iterator.hasNext()) {
			Customer customer = (Customer) iterator.next();

			CustomerBN customerBN = new CustomerBN();
			customerBN.setAddress(customer.getAddres());
			customerBN.setName(customer.getName());
			customerBN.setId(customer.getId());
			bns.add(customerBN);

		}

		return bns;
	}

}
